from __future__ import annotations

from dataclasses import dataclass
from math import cos, radians


@dataclass
class DerrickForceResult:
    compressive_kN: float
    base_shear_kN: float
    guy_tension_kN: float
    note: str


def analyze_derrick(
    load_kN: float,
    boom_angle_deg: float,
    boom_weight_kN: float = 2.0,
    num_guys: int = 3,
    safety_factor: float = 1.1,
) -> DerrickForceResult:
    """抱杆受力简化分析。

    - 以平面杆件为近似，取轴压 N ≈ (荷载+自重)/cosθ
    - 基底剪力取水平分量，缆风绳分担
    - 缆风绳拉力按均分估算
    """

    theta = radians(boom_angle_deg)
    axial = (load_kN + boom_weight_kN) / max(0.1, cos(theta)) * safety_factor
    shear = (load_kN + boom_weight_kN) * 0.2
    guy = shear / max(1, num_guys)
    return DerrickForceResult(
        compressive_kN=axial,
        base_shear_kN=shear,
        guy_tension_kN=guy,
        note="估算值，建议按空间受力与稳定复核",
    )


